package com.gitbl.webchat.server;

import com.gitbl.webchat.utils.ArgumentsHelper;
import groovyjarjarcommonscli.*;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.io.IOException;
import java.util.HashSet;
import java.util.Properties;
@SpringBootApplication
@EnableAutoConfiguration
public class Application {

    static void initdb(){

    }

    public static void main(String[] args) throws IOException, ParseException {

        HashSet<String> systemproperties=new HashSet();
        systemproperties.add("session.hosts");
        systemproperties.add("DUBBO_IP_TO_REGISTRY");
        systemproperties.add("DDUBBO_PORT_TO_REGISTRY");
        systemproperties.add("DUBBO_PORT_TO_BIND");
        Properties pps = ArgumentsHelper.parseProperties(args, "use value for given property(property=value) \neg: -Dzk=192.168.10.144:2181,192.168.10.144:2082" +
                "\\\n-DDUBBO_IP_TO_REGISTRY=192.168.1.102" +
                "\\\n-DDUBBO_PORT_TO_REGISTRY=20880" +
                "\\\n-DDUBBO_PORT_TO_BIND=20880"+
                "\\\n-Dsession.hosts=127.0.0.1:6379","webchat-server-room-1.0-SNAPSHOT.jar");
        if(pps==null){
            return;
        }

        for (Object p : pps.keySet()) {
            String k = p.toString();
            if(systemproperties.contains(k))
                System.setProperty(k, pps.getProperty(p.toString()));
        }


        new SpringApplicationBuilder(Application.class)
                .run(args);

    }
}
